/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Tracks an inventory item
 *
 * @author Andrew Juby
 * Estimated time: 1 hour
 * Actual time: 1:10 pm - 1:48 pm
 */
public class InventoryItem implements Comparable<InventoryItem> {
    private String name;
    private int uniqueItemID;

    /**
     * Creates an empty InventoryItem object
     */
    public InventoryItem(){
        this(0, "Nameless");
    }

    /**
     * Creates a new InventoryItem object with the given ID and no name
     * @param ID Identifier value assigned by the store
     */
    public InventoryItem(int ID){
        this(ID, "Nameless");
    }

    /**
     * Creates a new InventoryItem object with the given ID and name
     * @param ID Identifier value assigned by the store
     * @param name String containing the name of the item
     */
    public InventoryItem(int ID, String name){
        this.uniqueItemID = ID;
        this.name = name;
    }

    /**
     * Creates a clone of another item
     * @param oldItem The InventoryItem to be cloned
     */
    public InventoryItem(InventoryItem oldItem){
        this.name = oldItem.name;
        this.uniqueItemID = oldItem.uniqueItemID;
    }

    /**
     * Sets the item's ID
     * @param newID New identifier value
     */
    public void setID(int newID){
        this.uniqueItemID = newID;
    }

    /**
     * Sets the item's name
     * @param newName String containing the new name
     */
    public void setName(String newName){
        this.name = newName;
    }

    /**
     * Returns the the item's identifier
     * @return The identifier value
     */
    public int getID(){
        return this.uniqueItemID;
    }

    /**
     * Return's the item's name
     * @return
     */
    public String getName(){
        return this.name;
    }

    /**
     * Compares two InventoryItems via their identifiers
     * @param otherItem The InventoryItem to be compared to
     * @return The difference between this item's identifier and the otherItem's
     */
    public int compareTo(InventoryItem otherItem) {
        return this.uniqueItemID - otherItem.uniqueItemID;
    }

    @Override
    public boolean equals(Object o){
        if(o.getClass() != this.getClass()) return false;
        else{
            if(this.hashCode() == ((InventoryItem) o).hashCode()) return true;
            else return false;
        }
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 59 * hash + (this.name != null ? this.name.hashCode() : 0);
        hash = 59 * hash + this.uniqueItemID;
        return hash;
    }

    @Override
    public String toString(){
        return "ID: " + this.uniqueItemID + " | Name: " + this.name;
    }
}
